package com.grendel.tubeyourmind.core
{
	import flash.utils.getQualifiedClassName;
	
	import mx.controls.TextArea;
	
	/**
	 * Provides config information to all components and main application.
	 * A light facade over config and theming XML which provides some additional functionality.
	 */
	public class Debug
	{		
		/**
		 * Singleton instance variable.
		 * @private
		 */
		private static var instance:Debug;
		
		/**
		 * Provides caching capabilities for config params.
		 * @private
		 */
		private var _debugTA:TextArea;

		public function get debugTA():mx.controls.TextArea
		{
			return _debugTA;
		}

		public function set debugTA(value:TextArea):void
		{
			_debugTA = value;
		}

		
		////////////////////////////////////////////////////////////////////////////////
		// Constructor
		////////////////////////////////////////////////////////////////////////////////
		
		/**
		 * Constructor.
		 * Should not be called directly as this object is a singleton.
		 * Unfortunately AS3.0 does not support private constructors.
		 */
		public function Debug()
		{        
			if (instance)
			{
				var className:String = getQualifiedClassName(this);
				
				throw new Error(className + " can only be accessed through " + className
					+ ".getInstance()");
			}
		}
		
		////////////////////////////////////////////////////////////////////////////////
		// Setters / Getters
		////////////////////////////////////////////////////////////////////////////////

		////////////////////////////////////////////////////////////////////////////////
		// Methods
		////////////////////////////////////////////////////////////////////////////////
		
		/**
		 * Allows access to the singleton instance.
		 * @return ConfigManager singleton instance.
		 */		
		public static function getInstance():Debug
		{
			if(!instance)
			{		
				instance = new Debug();
			}
			return instance;
		}
		
		public function appendDebug(txt:String):void
		{
			if (debugTA)
				debugTA.text = txt + "\n" + debugTA.text;
		}
	}	
}
